#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <onenet.h>

#define DBG_TAG "onenet"
#define DBG_LVL         DBG_LOG
#include <rtdbg.h>

#include "demo.h"

static rt_uint8_t sem_flag=0;

static void onenet_entry(void *parameter)
{
    float upload[4];
    rt_thread_mdelay(20000);
    onenet_mqtt_init();
    LOG_D("onenet run\n");
    while(1){
        if (rt_mq_recv(&mq,upload,4*sizeof(float),RT_WAITING_FOREVER)==RT_EOK) {
            onenet_mqtt_upload_digit("humi", (int)upload[0]);
            rt_thread_mdelay(500);
            onenet_mqtt_upload_digit("temp", (int)upload[1]);
            rt_thread_mdelay(500);
            onenet_mqtt_upload_digit("brightness", (int)upload[2]);
            rt_thread_mdelay(500);
            onenet_mqtt_upload_digit("distance", 0);
            rt_thread_mdelay(500);
            //LOG_D("%d,%d,%d,%d",(int)upload[0],(int)upload[1],(int)upload[2],(int)upload[3]);
           // LOG_D("uploading data\n");
        }else{
            rt_thread_mdelay(500);
        }
    }

}
